package com.enhe.gck.fg;

import com.enhe.gck.communal.PublicMethod;
import com.enhe.gck.communal.PublicReturn;
import com.enhe.gck.item.CarHWANE16654Item;
import com.enhe.gck.pojo.Car;
import com.enhe.gck.pojo.Customer;
import com.enhe.gck.pojo.Driver;
import com.kuangkie.carbon.panel.CarbonPanel;
import com.kuangkie.carbon.record.RecordQueryProConJunctionFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import com.kuangkie.carbon.fg.FuncGroupContext;
import com.kuangkie.carbon.fg.ImproveResultFactory;
import com.kuangkie.carbon.fg.SecondRoundImproveFuncGroup;
import com.kuangkie.carbon.record.FGRecordComplexus;
import com.kuangkie.carbon.record.ProRecord;
import com.enhe.gck.CarbonBaseConstant; //模型Code
import com.enhe.gck.CarbonEnumKeyValue; //枚举字典信息
import com.enhe.gck.CarbonRelationType; //关系类型Code
import com.enhe.gck.item.DriverHWANE16665Item; // 模型属性Code

import java.util.List;

@Slf4j
@Repository(value = "hwane16665366042330866425862")
public class DriverHWANE16665BNB implements SecondRoundImproveFuncGroup{
	
	@Override
	public void secondImprove(FuncGroupContext context, ProRecord proRecord, FGRecordComplexus recordComplexus,
			ImproveResultFactory improveResultFactory) {
		Driver info=proRecord.getBean(Driver.class);

		if(proRecord.isNew()){
			improveResultFactory.getCurrentProRecordOpsBuilder().putAttribute(DriverHWANE16665Item.基本属性组_删除,false);

			if(String.valueOf(CarbonEnumKeyValue.操作命令_添加当前账户司机_tjdqzhsj).equals(info.getCommand())){
				log.info("添加当前账户司机");
				if(context.getUserCode()==null){
					PublicMethod.returnMessage(improveResultFactory, PublicReturn.USER_1);
					return;
				}
				RecordQueryProConJunctionFactory query= CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.客户管理_khgl).getProConJunctionFactory();
				query.getRelationCriterionFactory(CarbonBaseConstant.系统用户_xtyh)
						.setInRelationTypes(CarbonRelationType.RR_客户管理_账户_系统用户)
						.setInGuestCodes(context.getUserCode());

				List<String> list=query.goBack().queryCodes();
				if(list==null|| list.isEmpty()){
					PublicMethod.returnMessage(improveResultFactory, PublicReturn.USER_2);
					return;
				}
				for (String rId:list) {
					improveResultFactory.getCurrentProRecordOpsBuilder().addRelation(CarbonRelationType.RR_司机管理_客户名称_客户管理,rId);
				}
			}
		}
	}
	
}
